class Request {
	get(url, params) {
		return new Promise((resolve, reject) => {
			uni.showLoading({
				title: '请稍等...'
			})
			const user = uni.getStorageSync("user") || {}
			return uni.request({
				url: process.env.VUE_APP_BASE_URL + url,
				timeout: 10000,
				method: 'GET',
				data: params,
				header: {
					authorization: 'Bearer ' + user.token
				},
				success(res) {
					uni.hideLoading()
					resolve(res.data)
				},
				fail(err) {
					uni.hideLoading()
					reject(err)
				},
				complete() {
					uni.hideLoading()
				}
			});
		})
	}

	post(url, data) {
		return new Promise((resolve, reject) => {
			uni.showLoading({
				title: '请稍等...'
			})
			const user = uni.getStorageSync("user") || {}
			return uni.request({
				url: process.env.VUE_APP_BASE_URL+ url,
				timeout: 10000,
				method: 'POST',
				data: data,
				header: {
					authorization: 'Bearer ' + user.token
				},
				success(res) {
					uni.hideLoading()
					resolve(res.data)
				},
				fail(err) {
					uni.hideLoading()
					reject(err)
				},
				complete() {
					uni.hideLoading()
				}
			})
		})
	}
	
	put(url, data) {
		return new Promise((resolve, reject) => {
			uni.showLoading({
				title: '请稍等...'
			})
			const user = uni.getStorageSync("user") || {}
			return uni.request({
				url: process.env.VUE_APP_BASE_URL+ url,
				timeout: 10000,
				method: 'PUT',
				data: data,
				header: {
					authorization: 'Bearer ' + user.token
				},
				success(res) {
					uni.hideLoading()
					resolve(res.data)
				},
				fail(err) {
					uni.hideLoading()
					reject(err)
				},
				complete() {
					uni.hideLoading()
				}
			})
		})
	}
}

export default new Request()
